﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GamePlusClassLibrary;

namespace GamePlus
{
	public partial class Default : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
            if (!IsPostBack)
            {
                loadDicasDia();
                loadDestaquePrincipal();
            }
		}

        private void loadDicasDia()
        {
            //string sContent = "<ul class=\"glistver\">";

            //List<highlights> list = highlights.Listar(3);

            //list.ForEach(delegate(highlights obj) {
            //    games objGame = games.Load(obj._game_ID);
            //    string sLi = "<li>";

            //    if (obj._position.Equals(1) || obj._position.Equals(2))
            //        sLi = "<li class=\"big\">";

            //    sContent += sLi;
            //    sContent += "<a href=\"/Game.aspx?c="+ obj._game_ID.ToString() +"\" class=\"bdc5 item\">";
            //    sContent += "<img class=\"img bdc2\" src=\"" + getImgUrl(obj._game_ID) + "\" alt=\"\">";
            //    sContent += "<strong class=\"clr5\">" + getDescription(obj._title, 20) +"</strong>";
            //    sContent += "<span class=\"dtdesc\">"+ getDescription(objGame._highlight, 45) +"...</span></a></li>";
            //});

            //sContent += "</ul>";

            //divDicasDia.InnerHtml = string.Empty;
            //divDicasDia.InnerHtml = sContent;
        }

        private void loadDestaquePrincipal()
        {
            //List<games> lsGame = new List<games>();
            //List<highlights> lsHighlights = highlights.ListarDestaquePrincipal();
            
            //lsHighlights.ForEach(delegate(highlights objHighlight) {
            //    lsGame.Add(games.Load(objHighlight._game_ID));
            //});

            //dstqprn.InnerHtml = string.Empty;

            //string sContent = string.Empty;

            //int cont = 0;
            //lsGame.ForEach(delegate(games objGame) {
            //    if (cont.Equals(0))
            //    {
            //        sContent += "<li class=\"big\"><a href=\"/Game.aspx?c="+ objGame._ID.ToString() +"\" class=\"bdc5 item\">";
            //        sContent += "<img class=\"img bdc2\" src=\""+ getImgUrl(objGame._ID) +"\" alt=\"\">";
            //        sContent += "<strong>"+ objGame._name +"</strong><span class=\"star-rating\">";
            //        sContent += "<span style=\"width:"+ decimal.Round((ratings.getGameRate(objGame._ID)*2)*10, 0).ToString() +"%;\" class=\"current-rating\">Ótimo</span>";
            //        sContent += "</span><span class=\"dtdesc clr5\">"+ getDescription(objGame._highlight,45) + "...</span>";
            //        sContent += "<span class=\"fm-sub bgc3 bdc4\" href=\"#\">Jogar</span></a></li>";
            //    }
            //    else
            //    {
            //        sContent += "<li><a href=\"/Game.aspx?c="+ objGame._ID.ToString() +"\" class=\"bdc5 item\">";
            //        sContent += "<img class=\"img bdc2\" src=\""+ getImgUrl(objGame._ID) +"\" alt=\"\">";
            //        sContent += "<strong>" + objGame._name + "</strong><span class=\"dtdesc clr5\">" + getDescription(objGame._highlight, 45) + "...</span></a></li>";                
            //    }
            //    cont++;
            //});

            //dstqprn.InnerHtml = sContent;
        }

        private string getImgUrl(int id)
        {
            string sZero = string.Empty;
            int cont = 3 - id.ToString().Length;
            for (int i = 0; i < cont; i++)
                sZero += "0";

            return "http://www.otzee.com.br/images/games/000/000/" + sZero + id.ToString() + "/spotlight_normal.jpg";
        }

        private string getDescription(string text, int length)
        {
            if (text.Length > length)
                text = text.Substring(0, length);
            return text;
        }
	}
}